package com.kidback.bbloc259.util;

/**
 * Created by meikai on 2020/02/06.
 */
public class NumParseUtils {

    public static long parseLong(String longStr) {
        return parseLong(longStr, 0);
    }

    public static long parseLong(String longStr, long defaultValue) {
        if (longStr == null || longStr.length() == 0) {
            return 0;
        }

        try {
            return Long.parseLong(longStr);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static int parseInt(String intStr) {
        return parseInt(intStr, 0);
    }

    public static int parseInt(String longStr, int defaultValue) {
        if (longStr == null || longStr.length() == 0) {
            return 0;
        }

        try {
            return Integer.parseInt(longStr);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static double parseDouble(String doubleStr) {
        return parseDouble(doubleStr, 0);
    }

    public static double parseDouble(String doubleStr, double defaultValue) {
        if (doubleStr == null || doubleStr.length() == 0) {
            return 0;
        }

        try {
            return Double.parseDouble(doubleStr);
        } catch (Exception e) {
            return defaultValue;
        }
    }



    public static float parseFloat(String floatStr) {
        return parseFloat(floatStr, 0f);
    }

    public static float parseFloat(String floatStr, float defaultValue) {
        if (floatStr == null || floatStr.length() == 0) {
            return 0;
        }

        try {
            return Float.parseFloat(floatStr);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static int getInt(Integer integer) {
        if (integer == null) {
            return 0;
        }
        return integer.intValue();
    }

}
